
//
//  ParkingPayDetailCell.m
//  PropertyMananger
//
//  Created by bh on 17/3/10.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "ParkingPayDetailCell.h"
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) * 360

@implementation ParkingPayDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * CellID = @"ParkingPayDetailCellID";
    ParkingPayDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        
        cell = [[ParkingPayDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.titleLabel];
        // self.titleLabel.text = @"3月份物业费金额";
        
        self.titleLabel.textColor = BHColor(51, 51, 51);
        self.titleLabel.font = BHFont(18);
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).with.offset(15);
            make.top.equalTo(self).with.offset(35);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2, 25));
        }];
        
        UILabel * actualExpenses = [[UILabel alloc]init];
        [self.contentView addSubview:actualExpenses];
        
        actualExpenses.textAlignment = NSTextAlignmentLeft;
        actualExpenses.textColor = BHColor(102, 102, 102);
        actualExpenses.text = @"已入账";
        
        actualExpenses.font = BHFont(15);
        [actualExpenses mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(self.titleLabel.mas_bottom).with.offset(50);
            make.size.mas_equalTo(CGSizeMake(50, 25));
        }];
        
        self.actualExpenses = [[UILabel alloc]init];
        [self.contentView addSubview:self.actualExpenses];
        self.actualExpenses.textColor = BHColor(102, 102, 102);
        
        NSMutableAttributedString *noteStr1 = [[NSMutableAttributedString alloc] initWithString:@"4303.98 元"];
        NSRange redRange1 = NSMakeRange(0, [[noteStr1 string] rangeOfString:@" "].location);
        [noteStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange1];
        [self.actualExpenses setAttributedText:noteStr1];
        
        self.actualExpenses.font = BHFont(14);
        self.actualExpenses.textAlignment = NSTextAlignmentLeft;
        
        [self.actualExpenses mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.titleLabel).with.offset(0);
            make.top.equalTo(actualExpenses.mas_bottom).with.offset(-5);
            make.size.mas_equalTo(CGSizeMake(BHscreenW/2 - 30, 25));
        }];
        
        [self setupCircleView];
        
    }
    
    return self;
}
/**
 *  初始化圆形视图
 */
- (void)setupCircleView{
    
    
    self.circleView = [[FZHDrawCircleView alloc]initWithFrame:CGRectMake(BHscreenW - 120, 50, 100, 100)];
    [self.contentView addSubview:self.circleView];

    //2.彩色属性
     self.circleView.moneyNumLabel.text = @"停车缴费";
    self.circleView.colourFillColor = BHColor(255, 200, 68);//颜色
    self.circleView.normalFillColor = BHColor(221, 233, 244);
    self.circleView.colourStartAngle = 0;//起始点
    self.circleView.colourEndAngle = DEGREES_TO_RADIANS(self.currentNum/self.totalNum);
    
    
}

- (void)setModel:(LeaderModel *)model{
    
    _model = model;
    
    if (![model.PakingTotalFee isEqualToString:@""]) {
        
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(model.PakingTotalFee.floatValue/model.PakingTotalFee.floatValue);
        
        self.circleView.cateLabel.text = model.PakingTotalFee;
        
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元",model.PakingTotalFee]];
        NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@" "].location);
        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
        
        self.actualExpenses.attributedText = noteStr;

    }else{
    
     //  self.circleView.colourEndAngle = DEGREES_TO_RADIANS(1/model.PakingTotalFee.floatValue);
        
        self.circleView.cateLabel.text = @"0.00";
        
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 元",@"0.00"]];
        NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@" "].location);
        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
        
        self.actualExpenses.attributedText = noteStr;
    
    }
    if ([model.PakingTotalFee isKindOfClass:[NSNull class]] || [model.PakingTotalFee isEqualToString:@""]) {
        
        self.circleView.cateLabel.text = @"0.00";
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(0.001/600.0);
        
    }else{
        
        self.circleView.colourEndAngle = DEGREES_TO_RADIANS(model.PakingTotalFee.floatValue/model.PakingTotalFee.floatValue);
    }
    
    
    [self.circleView setNeedsDisplay];
    
    
    
}

@end
